package com.oocl.dojo.gildedrose.service;

import com.oocl.dojo.gildedrose.model.Item;
import com.oocl.dojo.gildedrose.strategy.Strategy;

public class ItemService {

    public void updateItem(Item item) {
        Strategy strategy = null;

        try {
            Class<?> c = Class.forName("com.oocl.dojo.gildedrose.strategy."
                    + item.getName().replaceAll("\\s", "")
                    + "Strategy");
            strategy = (Strategy) c.newInstance();
        } catch (ClassNotFoundException e) {
            strategy = new Strategy();
        } catch (IllegalAccessException | InstantiationException e) {
            e.printStackTrace();
        }

        if (strategy != null) {
            strategy.updateItem(item);
        }
    }
}
